package com.csun.cmny.provider.resolver;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Locale;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-01-18 11:59
 * @Description: the cmny message source
 */
@Slf4j
@Component
public class CmnyMessageSource {

    @Resource
    private MessageSource messageSource;

    @Resource
    private CmnyLocaleResolver cmnyLocaleResolver;

    public String getMessage(String code, Object[] param) {
        Locale locale = LocaleContextHolder.getLocale();
        log.debug("local = {}", locale.toString());
        return messageSource.getMessage(code, param, LocaleContextHolder.getLocale());
    }

}
